#!/usr/bin/env ruby
require 'net/ftp'
require 'find'


def uploadFile
    ftp = Net::FTP::new("ourpurpose.co.uk")
    ftp.login("ourpurp1", "TFJEBV8W")

    #ftp.chdir("/test")
    #tgz = ftp.list("ruby-*.tar.gz").sort.last
    #print "the latest version is ", tgz, "\n"
    #ftp.getbinaryfile(tgz, tgz)

    ftp.mkdir('test')
    ftp.chdir('test')

    directoryContents.each { |file| puts file
    #File.directory?
    #File.basename('C:\Documents and Settings\SNS User\My Documents\Projects\ourpurpose'))

    filesize = Float(File.size('C:\\file.txt'))
    data_sent = 0
    ftp.putbinaryfile('C:\\file.txt', File.basename(file)) { |data|
        data_sent += data.size
        percent = (data_sent/filesize)*100
        printf("Transfered : %i r", percent)
        $stdout.flush
    }
    print ftp.list('all')
    }

    ftp.close
end

def upload(file)
    filesize = Float(File.size(file))
    data_sent = 0
    ftp.putbinaryfile(file, File.basename(file)) { |data|
        data_sent += data.size
        percent = (data_sent/filesize)*100
        printf("Transfered : %i r", percent)
        $stdout.flush
    }
    print ftp.list('all')
end


def directoryContentsUpload
    ftp = Net::FTP::new("ourpurpose.co.uk")
    ftp.login("ourpurp1", "TFJEBV8W")

    file_paths = Array.new
    directories_to_scan = ['C:\\Documents and Settings\\SNS User\\My Documents\\Projects\\ourpurpose']
    excludes = ["CVS", "classes", "images", "lib", "tlds"]
    
    for dir in directories_to_scan
        Find.find(dir) do |path|
            if FileTest.directory?(path)
                if excludes.include?(File.basename(path))
                    Find.prune       # Don't look any further into this directory.
                else
                    ftp.mkdir(File.basename(dir))
                    file_paths.push(path)
                end
            else
                file_paths.push(path)
            end
        end
    end
    ftp.close
    file_paths
end

def directoryContents
    file_paths = Array.new
    directories_to_scan = ['C:\\Documents and Settings\\SNS User\\My Documents\\Projects\\ourpurpose']
    excludes = ["CVS", "classes", "images", "lib", "tlds"]
    for dir in directories_to_scan
        Find.find(dir) do |path|
            if FileTest.directory?(path)
                if excludes.include?(File.basename(path))
                    Find.prune       # Don't look any further into this directory.
                else
                    file_paths.push(path)
                end
            else
                file_paths.push(path)
            end
        end
    end
    file_paths
end


directoryContents.each { |file| puts file }


